<!--
 * Description: FD待接收页面
 * Company: 联宝（合肥）电子科技有限公司
 * Author: Qiuxue.Wu
 * Date: 2020/05/20 14:48
-->

<template>
  <div>
    <!--数据表单-->
    <el-form label-width="160px" :model="formData" size="mini">
      <el-row>
        <!--FD编号-->
        <el-col :span="12">
          <el-form-item :label="$t('FdData.fdId')">
            <span>{{ formData.fdId }}</span>
          </el-form-item>
        </el-col>

        <!--FD名称-->
        <el-col :span="12">
          <el-form-item :label="$t('FdData.fdName')">
            <span>{{ formData.fdName }}</span>
          </el-form-item>
        </el-col>

        <!--PBM负责人-->
        <el-col :span="24">
          <el-form-item :label="$t('FdData.pbmOwner')">
            <span>{{ $store.getters['user/getUserNameById'](formData.pbmOwner) }}</span>
          </el-form-item>
        </el-col>

        <!--产量(K)-->
        <el-col :span="12">
          <el-form-item :label="$t('FdData.volume')">
            <BaseInput
              v-model="formData.volume"
              :max="9999999999.99999999"
              :min="0"
              :placeholder="$t('input.placeholder')"
              :precision="1"
            />
            <!-- <el-input-number
              v-model="formData.volume"
              clearable
              controls-position="right"
              :precision="0"
            /> -->
          </el-form-item>
        </el-col>

        <!--项目推向市场时间-->
        <el-col :span="12">
          <el-form-item :label="$t('FdData.ss')">
            <el-date-picker
              v-model="formData.ss"
              :picker-options="pickerOptions"
              type="date"
              value-format="yyyy-MM-dd"
            />
          </el-form-item>
        </el-col>

        <!--ME负责人-->
        <el-col :span="12">
          <el-form-item :label="$t('FdData.meOwner')">
            <el-select
              v-model="formData.meOwner"
              clearable
              filterable
              :placeholder="$t('select.placeholder')"
            >
              <el-option
                v-for="item in $store.getters['user/getMEGcmUserSimpleCollects']"
                :key="item.userId"
                :label="item.userName"
                :value="item.userId"
              >
                <span style="float: left;">{{ item.userName }}</span>
                <span style="float: right; color: #b4b4b4; font-size: 12px">
                  {{ item.gcmFunction + ' ' + item.team }}
                </span>
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <!--EE负责人-->
        <el-col :span="12">
          <el-form-item :label="$t('FdData.eeOwner')">
            <el-select
              v-model="formData.eeOwner"
              clearable
              filterable
              :placeholder="$t('select.placeholder')"
            >
              <el-option
                v-for="item in $store.getters['user/getEEGcmUserSimpleCollects']"
                :key="item.userId"
                :label="item.userName"
                :value="item.userId"
              >
                <span style="float: left;">{{ item.userName }}</span>
                <span style="float: right; color: #b4b4b4; font-size: 12px">
                  {{ item.gcmFunction + ' ' + item.team }}
                </span>
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <!--PKG负责人-->
        <el-col :span="12">
          <el-form-item :label="$t('FdData.pkgOwner')">
            <el-select
              v-model="formData.pkgOwner"
              clearable
              filterable
              :placeholder="$t('select.placeholder')"
            >
              <el-option
                v-for="item in $store.getters['user/getPKGGcmUserSimpleCollects']"
                :key="item.userId"
                :label="item.userName"
                :value="item.userId"
              >
                <span style="float: left;">{{ item.userName }}</span>
                <span style="float: right; color: #b4b4b4; font-size: 12px">
                  {{ item.gcmFunction + ' ' + item.team }}
                </span>
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <span style="display: block;text-align: center;margin-top: 5px">
      <!--取消按钮-->
      <el-button size="medium" @click="cancel">{{ $t('button.cancel') }}</el-button>
      <!--保存按钮-->
      <el-button :loading="isRequesting" size="medium" type="primary" @click="save">
        {{ $t('button.save') }}
      </el-button>
    </span>
  </div>
</template>

<script>
import { fdReceive } from '@/api/quote/fd'

export default {
  name: 'FdReceiveComfirm',
  props: {
    inputData: {
      type: Object,
      default: () => null
    }
  },
  data() {
    return {
      // 正在查询
      isRequesting: false,
      formData: {},
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() < Date.now()
        }
      }
    }
  },
  mounted() {
    this.pageDataInit()
  },
  methods: {
    pageDataInit() {
      // 将props传入的值复制给formData的值
      this.formData = this.$deepCopy(this.inputData)
    },
    async save() {
      try {
        await this.$confirmBox(this.$t('button.save'), 'success')
        this.isRequesting = true
        await fdReceive(this.formData, { msgSuccess: true, msgError: true })
        this.$emit('save')
      } catch (error) {
        console.log(error)
      } finally {
        this.isRequesting = false
      }
    },
    cancel() {
      this.$emit('cancel')
    }
  }
}
</script>

<style scoped>
.el-form-item__content span {
  margin-left: 5px;
  color: blue;
}
</style>
